package org.example.chatroom.demos.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.chatroom.demos.model.Friend;
import org.example.chatroom.demos.model.User;
import org.example.chatroom.demos.service.FriendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@Slf4j
@RequestMapping("/friend")
@RestController
public class FriendController {
    @Autowired
    private FriendService friendService ;

    @RequestMapping("/getFriendList")
    public Object getFriendList(HttpSession httpSession){
        if(httpSession == null){
            log.info("session为null");
            return null ;
        }
        User user = (User) httpSession.getAttribute("USER_KEY");
        if(user == null || user.getId() == null){
            log.info("session的attribute(USER_KEY)为 null");
            return null ;
        }
        List<Friend> friendList =  friendService.getFriendList(user.getId());
         return friendList ;
    }

}
